package com.dshore.messagecenter.service.statistics.impl;


import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dshore.messagecenter.dao.statistics.MessageDao;
import com.dshore.messagecenter.model.system.SysDict;
import com.dshore.messagecenter.model.topicqueue.MdTopic;
import com.dshore.messagecenter.service.statistics.MessageService;
import com.dshore.messagecenter.util.Page;

@Service
public class MessageServiceImpl implements MessageService {
	
	private static final Logger Log = LoggerFactory.getLogger(MessageServiceImpl.class);
	
	@Autowired
	private MessageDao messageDao;

	@Override
	public List<Map<String,Object>> getMsgStatus() {
		return messageDao.getMsgStatus();
	}

	@Override
	public List<SysDict> getPeriod() {
		List<SysDict>list=messageDao.querryPeriod();
		return list;
	}
	
	public void insertCurrentKPI(List<Object[]> rabbitMqMonitor) {
		messageDao.insertCurrentKPI(rabbitMqMonitor);
	}

	@Override
	public Map<Object, Object> getTodayMessageFlowByTime() {
		Date d=new Date();
		DateFormat df=new SimpleDateFormat("yyyy-MM-dd ");
		String riqi=df.format(d);  //2018/08/01 
		Calendar now=Calendar.getInstance();
		List<Map<String, Object>>list=new ArrayList<>();
		Map<Object,Object> m=new HashMap<Object,Object>();
		list=messageDao.getTodayMessageFlowByTime(riqi);
		if(list!=null) {
			for(int i=0;i<list.size();i++) {
				Map map1 =(Map)list.get(i);//这是一个map集合，map集合中有两个元素 
				Object obj1=map1.get("A");
				Object obj2=map1.get("B");
				m.put(obj1, obj2);
			}
		}
		return m;
	}
	
	@Override
	public List<List<Object>> getTodayMessageFlowByTopic() {
		Date d=new Date();
		DateFormat df=new SimpleDateFormat("yyyy-MM-dd ");
		String riqi=df.format(d);  //2018/08/01 
		List<Map<String, Object>>list=new ArrayList<>();
		List<Object> topicLi=new ArrayList<>();
		List<Object> messageLi=new ArrayList<>();
		
		list=messageDao.getTodayMessageFlowByTopic(riqi);
		if(list!=null) {
			for(int i=0;i<list.size();i++) {
				Map<String,Object> map1 =list.get(i);//这是一个map集合，map集合中有两个元素 
				Object obj1=map1.get("name");
				Object obj2=map1.get("value");
				topicLi.add(obj1);
				messageLi.add(obj2);
			}
		}
		List<List<Object>>l =new ArrayList<>();
		l.add(topicLi);
		l.add(messageLi);
		return l;
	}
	
	@Override
	public Integer insertObj(SysDict t) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Page<Map<String, Object>> queryListAll(SysDict t) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public MdTopic queryById(String id) {
		// TODO Auto-generated method stub
		return null;
	}
	
	/**
	 * *******************查询过去七天消息流量   按照时间*********************
	 */
	@Override
	public List<Map<String, Object>>  getMessageByOptionByTimeId54(String optionId) {
		List<Map<String,Object>> list=messageDao.getMessageFlowFromLastSevenDaysByTime();
		return list;
	}

	/**
	 * *******************查询过去七天消息流量   按照主题队列****************
	 */
	@Override
	public List<Map<String, Object>> getMessageByTopicByOptionId54(String optionId) {
		Date d=new Date();
		DateFormat df=new SimpleDateFormat("yyyy-MM-dd ");
		Calendar c=Calendar.getInstance();
		c.setTime(d);
		c.add(Calendar.DATE, -6);
		Date da=c.getTime();
		String riqi=df.format(d);  //本日2018/08/01 
		String qitian=df.format(da);  //七天前
		List<Map<String,Object>> list=messageDao.getMessageFlowFromLastSevenDaysByTopic(riqi,qitian);
		return list;
	}
	
	/**
	 * *******************查询过去30天消息流量   按照主题队列****************
	 */
	@Override
	public List<Map<String, Object>> getMessageByTopicByOptionId55(String optionId) {
		Date d=new Date();
		DateFormat df=new SimpleDateFormat("yyyy-MM-dd ");
		Calendar c=Calendar.getInstance();
		c.setTime(d);
		c.add(Calendar.DATE, -29);
		Date da=c.getTime();
		String riqi=df.format(d);  //本日2018/08/01 
		String qitian=df.format(da);  //30天前
		List<Map<String,Object>> list=messageDao.getMessageFlowFromLastMonthByTopic(riqi,qitian);
		return list;
	}
	
	/**
	 * *******************查询过去30天消息流量   按照时间*********************
	 */
	@Override
	public List<Map<String, Object>> getMessageByOptionByTimeId55(String optionId) {
		List<Map<String,Object>> list=messageDao.getMessageFlowFromLastMonthDaysByTime();
		return list;
	}





	
}
